package cn.edu.buaa.cnsatm.traffic_big_data_server.waterway.dao;

import cn.edu.buaa.cnsatm.traffic_big_data_server.util.JDBCUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PortDAO {
    public static ResultSet getTopKPortCongestion(int k){
        /**
         * @author LX
         * @description 查询港口拥挤度，目前是写死的
         * @date 2019-11-06
         */
        String sql = "SELECT port_name, congestion FROM port_point ORDER BY congestion DESC LIMIT " + String.valueOf(k);
        String sql1 = "SELECT max(congestion) as max FROM port_point";
        Statement stmt = null;
        ResultSet resultSet = null;
        try {
            stmt = JDBCUtil.databaseConnecttion.createStatement();
            resultSet= stmt.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return resultSet;
    }

    public static ResultSet getAllPortNameAndLocation(){
        /**
         * @author LX
         * @description 获取港口名与港口经纬度
         * @date 2019-11-06
         */
        String sql = "SELECT st_astext(geom) as geom, port_name FROM port_point";
        Statement stmt = null;
        ResultSet resultSet = null;
        try {
            stmt = JDBCUtil.databaseConnecttion.createStatement();
            resultSet= stmt.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return resultSet;
    }
}
